import axios from "axios";

const apiClient = axios.create({
  baseURL: "/api", // Replace with your API base URL 
  headers: {
    "Content-Type": "application/json",
  },
});

export default {
    get: async (url, params = {}) => {
        try {
        const response = await apiClient.get(url, { params });
        return response.data;
        } catch (error) {
        console.error("API GET Error:", error);
        throw error;
        }
    },
    
    post: async (url, data = {}) => {
        try {
        const response = await apiClient.post(url, data);
        return response.data;
        } catch (error) {
        console.error("API POST Error:", error);
        throw error;
        }
    },
    
    put: async (url, data = {}) => {
        try {
        const response = await apiClient.put(url, data);
        return response.data;
        } catch (error) {
        console.error("API PUT Error:", error);
        throw error;
        }
    },
    
    delete: async (url) => {
        try {
        const response = await apiClient.delete(url);
        return response.data;
        } catch (error) {
        console.error("API DELETE Error:", error);
        throw error;
        }
    },
}